class Tube:
    def __init__(self, l, w, n):
        self.l, self.w, self.n = l, w, n

    def __str__(self):
        return str(self.n)

    def __lt__(self, other):
        if self.l != other.l:
            return self.l > other.l
        if self.w != other.w:
            return self.w < other.w

        return self.n > other.n


n = int(input())
for i in range(n):
    m = int(input())
    a = list()
    for j in range(m):
        l, w, n = map(int, input().strip().split())
        a.append(Tube(l, w, n))
    a.sort()
    print(a[0])
